package org.huoran.sakamichi.main.controller;

import org.apache.commons.lang3.StringUtils;
import org.huoran.sakamichi.main.util.Global;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping({"/webSocket"})
public class WebSocketController {

    private static final String WEB_SOCKET_PORT_KEY = "wsPort";
    private static final String USERNAME_KEY = "name";

    @RequestMapping(value = {"/toWebSocket/{name}"})
    public String toWebSocket(Model model, @PathVariable String name){
        if(StringUtils.isNoneEmpty(name)){
            model.addAttribute(WEB_SOCKET_PORT_KEY, Global.getConfig("webSocket.port"));
            model.addAttribute(USERNAME_KEY, name);
            return "/WebSocketClient";
        }
        else{
            return null;
        }
    }

}
